package com.tiankong.product.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.experimental.Accessors;
import net.youdi.common.em.YesOrNo;
import net.youdi.common.model.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 商品三级分类
 * </p>
 *
 * @author scl
 * @since 2021-03-22
 */
@Data
@Accessors(chain = true)
@TableName("t_category")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class Category implements TreeNode {

    /**
     * 分类id
     */
    @TableId(value = "cat_id", type = IdType.AUTO)
    private Long catId;

    /**
     * 分类名称
     */
    private String name;

    /**
     * 父分类id
     */
    private Long parentCid;

    /**
     * 层级
     */
    private Integer catLevel;

    /**
     * 是否显示[0-不显示，1显示]
     */
    @TableLogic(value = YesOrNo.YES,delval = YesOrNo.NO)
    private Integer showStatus;

    /**
     * 排序
     */
    private Integer sort;

    /**
     * 图标地址
     */
    private String icon;

    /**
     * 计量单位
     */
    private String productUnit;

    /**
     * 商品数量
     */
    private Integer productCount;

    @TableField(exist = false)
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List children = new ArrayList<>();

    @TableField(exist = false)
    @JsonIgnore
    private Category parent;

    @Override
    public void setParent(TreeNode parent) {
        this.parent = (Category) parent;
    }

    @Override
    public Object getId() {
        return catId;
    }

    @Override
    @JsonIgnore
    public Object getParentId() {
        return this.parentCid;
    }

    @Override
    public String getCode() {
        return null;
    }

    @Override
    public Object setCode(String s) {
        return null;
    }

    @Override
    public TreeNode getParent() {
        return this.parent;
    }
}
